<template>
  <div>
    <div class="pswWrapper">
      <div class="pswzHead">
        <span class="txt">修改密码</span>
        <div class="icon">
          <i class="el-icon-close"></i>
        </div>
      </div>
      <div class="hr1"></div>

      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="旧密码" prop="pass">
          <el-input
            type="password"
            v-model="ruleForm.pass"
            autocomplete="off"
            placeholder="请填写旧密码，6至32个字符之间"
          ></el-input>
        </el-form-item>
        <el-form-item label="新密码" prop="checkPass">
          <el-input
            type="password"
            v-model="ruleForm.checkPass"
            autocomplete="off"
            placeholder="请填写新密码，6至32个字符之间"
          ></el-input>
        </el-form-item>
        <div class="hr2"></div>

        <el-form-item>
       <div class="btn">
              <el-button @click="resetForm('ruleForm')">取消</el-button>
          <el-button type="primary" @click="submitForm('ruleForm')"
            >确定</el-button
          >
       </div>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  name: "ChangePsw",
  data() {
    var validatePass = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入密码"));
      } else {
        if (this.ruleForm.checkPass !== "") {
          this.$refs.ruleForm.validateField("checkPass");
        }
        callback();
      }
    };
    var validatePass2 = (rule, value, callback) => {
      if (value === "") {
        callback(new Error("请输入新密码"));
      } else if (value == this.ruleForm.pass) {
        callback(new Error("两次输入密码不能一致!"));
      } else {
        callback();
      }
    };
    return {
      ruleForm: {
        pass: "",
        checkPass: "",
      },
      rules: {
        pass: [{ validator: validatePass, trigger: "blur" }],
        checkPass: [{ validator: validatePass2, trigger: "blur" }],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          alert("submit!");
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
   
  },
};
</script>

<style scoped>
.pswWrapper {
  width: 700px;
  height: 350px;
  position: absolute;
  top: -150px;
  right: 400px;
  border: 1px solid silver;
  background-color: #fff;
  border-radius: 2px;
}
.pswHead {
  display: flex;
  flex-direction: column;
  position: relative;
}
.txt {
  font-size: 24px;
  color: #333;
  position: absolute;
  left: 40px;
}
.el-icon-close {
  font-size: 24px;
}

.icon {
  width: 40px;
  height: 40px;
  position: absolute;
  right: 20px;
}

.demo-ruleForm {
  margin-top: 40px;
}

.hr1 {
  width: 700px;
  height: 1px;
  background-color: #ababab;

  margin-top: 60px;
}
.hr2 {
  width: 700px;
  height: 1px;
  background-color: #ababab;

  margin-top: 50px;
  margin-bottom: 20px;
}
.input {
  width: 200px;
}
.btn{
    position: absolute;
    right: 40px;
}
</style>